/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgGuideStep
    {
        private readonly Dictionary<int, CfgGuideStep> _dataMap;
        private readonly List<CfgGuideStep> _dataList;


        public TbCfgGuideStep(ByteBuf _buf)
        {
            //first read common data
            _TbCommonGuideStep _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonGuideStep(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgGuideStep>(size * 3 / 2);
            _dataList = new List<CfgGuideStep>(size);

            for (int i = 0; i < size; i++)
            {
                CfgGuideStep _v;
                _v = CfgGuideStep.DeserializeCfgGuideStep(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgGuideStep> DataMap => _dataMap;
        public IReadOnlyList<CfgGuideStep> DataList => _dataList;

        public CfgGuideStep Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgGuideStep] config not found,id:" + key.ToString());

            return null;
        }

        public CfgGuideStep GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "guidestep";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgGuideStep LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgGuideStep(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgGuideStep
    {
        private CfgGuideStep(ByteBuf _buf, _TbCommonGuideStep _commonData)
        {
            Id = _buf.ReadInt();
            Order = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; GuideSubShow = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; NpcTalk = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ClickArea = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; PlayEffect = _commonData._field3[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; ShowPicture = _commonData._field4[dataIndex]; }
            FunctionID = _buf.ReadInt();

            PostInit();
        }

        internal static CfgGuideStep DeserializeCfgGuideStep(ByteBuf _buf, _TbCommonGuideStep _commonData)
        {
            return new CfgGuideStep(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 顺序
        /// </summary>
        public int Order { get; private set; }
        /// <summary>
        /// 显示引导所需展示组件
        /// </summary>
        public string GuideSubShow { get; private set; }
        /// <summary>
        /// 说话类型引导
        /// </summary>
        public IReadOnlyList<string> NpcTalk { get; private set; }
        /// <summary>
        /// 点击区域
        /// </summary>
        public string ClickArea { get; private set; }
        /// <summary>
        /// 使用特效
        /// </summary>
        public string PlayEffect { get; private set; }
        /// <summary>
        /// 展示图片
        /// </summary>
        public string ShowPicture { get; private set; }
        /// <summary>
        /// 跳转ID
        /// </summary>
        public int FunctionID { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonGuideStep
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<string>> _field1 { get; private set; }
        internal IReadOnlyList<string> _field2 { get; private set; }
        internal IReadOnlyList<string> _field3 { get; private set; }
        internal IReadOnlyList<string> _field4 { get; private set; }
        internal _TbCommonGuideStep(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new string[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ string __v1; __v1 = _buf.ReadString(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
